<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class SetupBasketHistoriesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //

        // Creates the users table
        Schema::create('basket_histories', function ($table) {
            $table->increments('id');
            $table->integer('member_id')->unsigned()->default(0)->comment('会员ID');
            $table->integer('menu_id')->unsigned()->default(0)->comment('菜单ID');
            $table->integer('food_id')->unsigned()->default(0)->comment('食物ID');
//            $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID');

            $table->string('menu_name',50)->nullable()->comment('菜单名称');
            $table->string('menu_keyword',50)->nullable()->comment('菜单关键字');

            $table->string('member_nick_name',50)->nullable()->comment('会员昵称');
            $table->string('member_phone',50)->nullable()->comment('手机号');
            $table->string('member_name',50)->nullable()->comment('姓名');

            $table->string('food_name',50)->nullable()->comment('食物名称');
            $table->decimal('food_original_price',6,2)->default(0)->comment('原价');
            $table->decimal('food_price', 6, 2)->default(0)->comment('现价');

            $table->integer('count')->unsigned()->default(0)->comment('数量');
            $table->enum('status', array("TIMEOUT","SOLD"))->comment('状态：过期，已销售');
            $table->timestamps();

//            $table->foreign('menu_id')->references('id')->on('menus');
//            $table->foreign('member_id')->references('id')->on('members');
//            $table->foreign('food_id')->references('id')->on('foods');

            $table->index('member_id');
            $table->index('menu_id');
            $table->index('food_id');
            $table->index('member_phone');
            $table->index('food_original_price');
            $table->index('food_price');
            $table->index('count');
            $table->index('status');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
//        Schema::table('basket_histories', function(Blueprint $table) {
//            $table->dropForeign('basket_histories_member_id_foreign');
//            $table->dropForeign('basket_histories_menu_id_foreign');
//            $table->dropForeign('basket_histories_food_id_foreign');
//        });
        Schema::drop('basket_histories');
    }


}
